package com.kucai.yifaqapp.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by on 2017/2/22.
 * 手机号正则判断
 */

public class Phoneutil
{
    public static boolean isEmail(String email) {
        String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
        Pattern p = Pattern.compile(str);
        Matcher m = p.matcher(email);
        return m.matches();
    }
    public static boolean isMobileNO(String mobiles){
        Pattern p = Pattern.compile("^[1][3,4,5,6,7,8][0-9]{9}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    public static boolean isFile(){
        File file = new File(Environment.getExternalStorageDirectory().toString()+"/cameras/image.png");
        if(file.exists())
            return true;
        return false;
    }
    public static void getDiskBitmap(ImageView view)
    {
        String pathString = Environment.getExternalStorageDirectory().toString()+"/cameras/image.png";
        Bitmap bitmap = null;
        try
        {
            File file = new File(pathString);
            if(file.exists())
            {
                bitmap = BitmapFactory.decodeFile(pathString);
                view.setImageBitmap(bitmap);
            }
        } catch (Exception e)
        {
            // TODO: handle exception
        }
    }
    public static void hintKbTwo(Activity act) {
        InputMethodManager imm = (InputMethodManager)act.getSystemService(Context.INPUT_METHOD_SERVICE);
        if(imm.isActive()&&act.getCurrentFocus()!=null){
            if (act.getCurrentFocus().getWindowToken()!=null) {
                imm.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    }
}
